import java.util.Comparator;

import javax.rmi.CORBA.Util;



public class PolarOrder implements Comparator<Point> {

	Point minYCoord = null;
	
	public PolarOrder(Point p) {
		super();
		minYCoord = p;
	}
	
	
	@Override
	public int compare(Point p1, Point p2) {
		//Not checking for null/empty pts
		
		if (p1 == p2)
			return 0;
		
		int crossProd = PointUtil.crossProdVectors(minYCoord, p1, p2);
		//System.out.println("--> xp: " + p1 +"x" + p2 + crossProd);
		if (crossProd == 0) {
			if (p1.getDistToYMin() < p2.getDistToYMin())
				return -1;
			else if (p1.getDistToYMin() > p2.getDistToYMin())
				return 1;
			else 
				return 0;
		}
		else if (crossProd > 0)
			return -1;
		else 
			return 1;
	}

	public Point getMinYCoord() {
		return minYCoord;
	}


	public void setMinYCoord(Point minYCoord) {
		this.minYCoord = minYCoord;
	}

}
